﻿<!doctype html>
<html>
<head>
    <title>SpreadJS - Picture</title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <link href="../../../external/spreadjs/css/gcspread.sheets.excel2013white.9.40.20161.0.css" rel="stylesheet" type="text/css" />

    <script src="../../../external/external/jquery-1.8.2.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="../../../external/spreadjs/gcspread.sheets.all.9.40.20161.0.min.js"></script>

    <style type="text/css">
    /*css_begin*/
        label {
            display:inline-block;
            width: 100px;
        }

        input[type="text"] {
            width: 80px;
            margin-right: 20px;
        }

        select {
            width: 84px;
            margin-right: 20px;
        }

        input[type="button"] {
            width: 140px;
            margin-right: 30px;
            margin-left: 30px;
        }
    /*css_end*/
    </style>

    <script id="scriptInit" type="text/javascript">
        /*code_begin*/
        $(document).ready(function () {
            var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"));
            initSpread(spread);
        });

        function initSpread(spread) {
            var sheet = spread.getSheet(0);
            var picture = sheet.addPicture("f2", "images/logo.png", 1, 1, 10, 4);
            picture.backColor("black");

            $("#pictureStretch").change(function () {
                var sheet = spread.getActiveSheet();
                var pictures = sheet.getPictures();
                var stretch = parseInt($(this).val());
                if (pictures) {
                    for (var index = 0, len = pictures.length;index < len; index++) {
                        var picture = pictures[index];
                        if (picture.isSelected()) {
                            picture.pictureStretch(stretch);
                        }
                    }
                }
            });
            $("#borderStyle").change(function () {
                var sheet = spread.getActiveSheet();
                var pictures = sheet.getPictures();
                var borderStyle = $(this).val();
                if (pictures) {
                    for (var index = 0, len = pictures.length;index < len; index++) {
                        var picture = pictures[index];
                        if (picture.isSelected()) {
                            picture.borderStyle(borderStyle);
                        }
                    }
                }
            });

            $("#set").click(function () {
                var sheet = spread.getActiveSheet();
                var pictures = sheet.getPictures();
                var borderColor = $("#borderColor").val();
                var borderWidth = parseFloat($("#borderWidth").val());
                var borderStyle = $("#borderStyle").val();
                var borderRadius = parseFloat($("#borderRadius").val());
                var backColor = $("#backColor").val();
                var pictureStretch = parseInt($("#pictureStretch").val());
                if (pictures) {
                    for (var index = 0, len = pictures.length;index < len; index++) {
                        var picture = pictures[index];
                        if (picture.isSelected()) {
                            picture.borderColor(borderColor);
                            picture.borderWidth(borderWidth);
                            picture.borderStyle(borderStyle);
                            picture.borderRadius(borderRadius);
                            picture.backColor(backColor);
                            picture.pictureStretch(pictureStretch);
                        }
                    }
                }
                sheet.repaint();
            });

            $("#resetPicture").click(function () {
                var sheet = spread.getActiveSheet();
                var pictures = sheet.getPictures();
                if (pictures) {
                    for (var index = 0, len = pictures.length;index < len; index++) {
                        var picture = pictures[index];
                        if (picture.isSelected()) {
                            var originalWidth = picture.getOriginalWidth();
                            var originalHeight = picture.getOriginalHeight();
                            if (originalWidth > 0 && originalHeight > 0) {
                                picture.width(originalWidth);
                                picture.height(originalHeight);
                            }
                        }
                    }
                }
                sheet.repaint();
            });
        };
        /*code_end*/
    </script>

</head>
<body>
    <div class="sample-turtorial">
        <div id="ss" style="width: 100%; height: 340px; border: 1px solid gray;"></div>
        <div class="demo-options">
            <div class="option-row">
                <label for="borderColor">Border Color:</label>
                <input type="text" id="borderColor" />
                <label for="borderWidth">Border Width:</label>
                <input type="text" id="borderWidth" />
            </div>
            <div class="option-row">
                <label for="borderRadius">Border Radius:</label>
                <input type="text" id="borderRadius" />
                <label for="backColor">Back Color:</label>
                <input type="text" id="backColor" />
            </div>
            <div class="option-row">
                <input type="button" id="set" value="Set" />
                <input type="button" id="resetPicture" value="Reset to original size" />
            </div>
            <div class="option-row">
                <label>Border Style:</label>
                <select id="borderStyle">
                    <option value="solid" selected="selected">solid</option>
                    <option value="dotted">dotted</option>
                    <option value="dashed">dashed</option>
                    <option value="double">double</option>
                    <option value="groove">groove</option>
                    <option value="ridge">ridge</option>
                    <option value="inset">inset</option>
                    <option value="outset">outset</option>
                </select>
                <label>Picture Stretch:</label>
                <select id="pictureStretch">
                    <option value="0" selected="selected">Stretch</option>
                    <option value="1">Center</option>
                    <option value="2">Zoom</option>
                    <option value="3">None</option>
                </select>
            </div>
        </div>
    </div>
</body>
</html>
